import 'dart:io';
import 'dart:ui';
import 'package:aio/aio.dart';
import 'package:aio/aio.dart' as aio;
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/config/app_data_config.dart';
import 'package:app/src/http/bean/wroks/search_bean.dart';
import 'package:app/src/http/bean/ywx_limit.dart';
import 'package:app/src/ui/dialog/dailog.dart';
import 'package:app/src/ui/popuwindow/popuwindow_search.dart';
import 'package:app/src/ui/route/helper/route_helper.dart';
import 'package:app/src/utils/image_path_utils.dart';
import 'package:easy_refresh/easy_refresh.dart';

import 'route/works/public/review_submitted.dart';

///常用ui
class AppUi {
  //hero动画tag标识
  static String hero_tag_launch = "hero_tag_launch";

  ///占位组件，只占空间，不作渲染。
  static Widget getSizeBox({double width = 0, double height = 0}) {
    return SizedBox.fromSize(
      size: Size(width, height),
    );
  }

  ///获取空白组件
  static Widget getEmptyViewWithSliver() {
    return SliverToBoxAdapter(
      child: SizedBox.shrink(),
    );
  }

  ///获取标题
  static Widget getTitle(String? title) {
    var text = title ?? "";
    return Text(
      text,
      style: TextStyle(color: Colors.black, fontSize: 18),
    );
  }

  ///获取AppBar右边的按钮
  ///callback 点击事件
  ///text 文本
  static Widget getRightAction(
      BuildContext context, ResponseCallbackWithVoid? callback,
      {String? text}) {
    if (text == null) {
      text = AppStrings.of(context).search; //默认搜索
    }
    return SafeArea(
        child: InkWell(
      child: Center(
        child: Padding(
          padding: EdgeInsets.only(left: 16, right: 16),
          child: Text(
            text,
            style: TextStyle(color: Colors.blueAccent, fontSize: 18),
          ),
        ),
      ),
      onTap: () {
        //搜索回调
        callback?.call();
      },
    ));
  }

  ///右边跳转图标(和返回键方向相反)
  static Widget getRightGo({EdgeInsetsGeometry padding = EdgeInsets.zero}) {
    return Padding(
      padding: padding,
      child: Icon(
        IconsUtils.back_right_7f3,
        color: ColorUtils.parseColor("#3D3D3D"),
      ),
    );
  }

  ///返回键
  ///ResponseCallbackWithVoidResult 回调；返回true就不作处理，返回false就直接返回
  static Widget getBack(
      BuildContext context, ResponseCallbackWithVoidResult? callback,
      {Color color = Colors.black, bool isCha = false}) {
    Icon ic;
    if (isCha) {
      ic = Icon(
        IconsUtils.chacha, //叉叉
        color: color,
      );
    } else {
      ic = Icon(
        IconsUtils.back_left_669, //fixme 返回键
        color: color,
      );
    }

    return SafeArea(
        child: InkWell(
      child: ic,
      onTap: () {
        //返回
        if (callback != null) {
          var b = callback.call(); //true 已经处理返回事件，不需要再处理。
          if (!b) {
            AppRouteHelper.pop(context);
          }
        } else {
          AppRouteHelper.pop(context);
        }
      },
    ));
  }

  ///获取通用统一Scaffold
  ///body 内容子组件
  ///title 标题
  static Scaffold getScaffold(
    BuildContext context,
    Widget body,
    String? title,
  ) {
    var scaffold = Scaffold(
      backgroundColor: AppColors.backgroundColorWithWhite,
      appBar: AppBar(
        backgroundColor: AppColors.backgroundColorWithWhite,
        elevation: 0,
        leading: getBack(context, () {
          return false;
        }),
        leadingWidth: 33,
        titleSpacing: 0,
        title: getTitle(title),
      ),
      body: Material(color: AppColors.backgroundColorWithGrey, child: body),
    );
    return scaffold;
  }

  ///static GlobalKey _globalKeyglobalKey = GlobalKey();///fixme 这个GlobalKey不要静态公用；多个页面公用会报错，只能给一个组件用。

  ///获取审核统一Scaffold
  ///body 内容子组件
  ///data 数据
  ///searchInfo 搜索添加
  ///onPressed 搜索点击回调
  ///hasSearch 是否有搜索条件
  ///scan 是否有扫一扫
  ///scanName 扫一扫图标名称
  ///scanCallBack 扫描返回结果
  static Scaffold getScaffoldWithReView(BuildContext context, Widget body,
      YwxItem? data, SearchInfo? searchInfo, VoidCallback? onPressed,
      {String? title = null,
      bool hasSearch = true,
      bool scan = false,
      String? scanName,
      ResponseCallbackWithString? scanCallBack,
      Widget? bottoUi}) {
    List<Widget>? actions = null;
    GlobalKey? globalKeyglobalKey = null;
    if (StringUtils.isEmpty(title)) {
      title = data?.YwxName;
      // if (StringUtils.isNotEmpty(data?.YwxName2)) {
      //   title = data?.YwxName2;
      // }
    }
    //print("=====================================================================${data?.YwxName}");
    if (searchInfo != null) {
      GlobalKey _globalKeyglobalKey = GlobalKey();
      globalKeyglobalKey = _globalKeyglobalKey;
      //搜索条件
      if (hasSearch) {
        actions = [];
        if (scan) {
          //扫一扫
          if (StringUtils.isEmpty(scanName)) {
            scanName = AppStrings.of(context).scan;
          }
          var item = Column(
            children: [
              Image.asset(
                ImagePathUtils.getPathWithImage("ic_menu_scan1.png"),
                width: 24,
              ),
              SizedBox(
                height: 4,
              ),
              Text(
                "$scanName" ?? "",
                style: TextStyle(color: Colors.black, fontSize: 10),
              )
            ],
            mainAxisAlignment: MainAxisAlignment.center,
          );
          actions.add(Listener(
            child: item,
            onPointerUp: (value) {
              AppRouteHelper.goScanRoute(context, (value) {
                if (value != null) {
                  //扫描结果
                  scanCallBack?.call(value);
                }
              });
            },
          ));
        }
        actions?.add(getRightAction(context, () {
          //搜索
          showPopuMenuWithSearch(context, data,
              globalKey: _globalKeyglobalKey,
              searchInfo: searchInfo,
              onPressed: onPressed);
        }));
      }
    }

    var scaffold = Scaffold(
      backgroundColor: AppColors.backgroundColorWithWhite,
      appBar: AppBar(
        key: globalKeyglobalKey,
        //fixme 搜索框位置
        backgroundColor: AppColors.backgroundColorWithWhite,
        elevation: 0,
        leading: getBack(context, () {
          return false;
        }),
        leadingWidth: 33,
        titleSpacing: 0,
        title: getTitle(title),
        actions: actions,
      ),
      body: Material(color: AppColors.backgroundColorWithGrey, child: body),
      bottomNavigationBar: bottoUi,
    );
    return scaffold;
  }

  ///搜索添加子布局
  ///text 文本
  ///onTap 删除点击事件
  ///onTapText 文本删除点击事件
  static Widget searchChild(
      BuildContext context, String text, GestureTapCallback? onTap,
      {GestureTapCallback? onTapText, bool isDel = true}) {
    List<Widget> children = [];
    if (onTapText == null) {
      children.add(InkWell(
        child: Text(text),
      ));
    } else {
      children.add(InkWell(
        child: Text(
          text,
          style: TextStyle(color: Colors.blueAccent),
        ),
        onTap: onTapText,
      ));
    }
    if (onTap != null && isDel) {
      children.add(InkWell(
        onTap: onTap,
        child: Padding(
          child: Icon(Icons.clear),
          padding: EdgeInsets.symmetric(horizontal: 8),
        ),
      ));
    }
    Widget child = Card(
      color: Colors.white,
      surfaceTintColor: Colors.transparent,
      shadowColor: Colors.black,
      //阴影颜色
      elevation: 5,
      //阴影长度
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(30))),
      child: Padding(
        padding: EdgeInsets.only(left: 8, right: 8, top: 6, bottom: 6),
        child: Row(
          children: children,
        ),
      ),
    );
    return child;
  }

  ///获取搜索条件布局
  ///onPressed 点击删除或清空回调
  static Widget getSearchLayout(
    BuildContext context,
    SearchInfo searchInfo,
    VoidCallback? onPressed, {
    YwxItem? ywxItem = null,
    VoidCallback? ywxItemCallback,
  }) {
    return StatefulBuilder(
      builder: (BuildContext context, StateSetter setState) {
        List<Widget> children = [];
        if (ywxItem?.YwxName2 != null && searchInfo.isShowRequisitionStatus) {
          //物料请购
          if (StringUtils.isNotEmpty(searchInfo.RequisitionStatus)) {
            Widget child = searchChild(
                context,
                AppStrings.of(context).MaterialRequisition +
                    ":" +
                    ywxItem!.YwxName2!,
                null, onTapText: () {
              var ReviewType2 = ywxItem.ReviewType2;
              AppDialog.showDialogWithPickerMaterialRequisition(
                  context, ywxItem, () {
                if (ReviewType2 != ywxItem.ReviewType2) {
                  ywxItemCallback?.call(); //类型发生改变再回调。
                }
              });
            });
            children.add(child);
          }
        }
        //审核状态
        if (searchInfo.isShowStatus &&
            StringUtils.isNotEmpty(searchInfo.getStatusOrderType(context))) {
          var isDel = true;
          if (!searchInfo.isShowStatusAll) {
            //审核状态，没有全显示选项时，不能删除。
            isDel = false;
          }
          Widget child = searchChild(
              context,
              AppStrings.of(context).AuditStatus +
                  ":" +
                  searchInfo.getStatusOrderType(context)!, () {
            setState(() {
              searchInfo.setStatusOrderType(null, isDel: true);
            });
            onPressed?.call();
          }, isDel: isDel);
          children.add(child);
        }

        ///fixme 通用搜索条件，放在审核状态后面。
        searchInfo.searchDatas?.forEach((element) {
          if (element.isShow && StringUtils.isNotEmpty(element.showValue)) {
            var showName = element.showName ?? "";
            var showValue = element.showValue ?? "";
            Widget child =
                searchChild(context, showName + ":" + showValue!, () {
              setState(() {
                element.clear();
              });
              onPressed?.call();
            });
            children.add(child);
          }
        });
        //所属工厂
        if (searchInfo.isShowFactory &&
            searchInfo.factory?.FactoryName != null) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).FactoryOfOwnership +
                  ":" +
                  searchInfo.factory!.FactoryName, () {
            setState(() {
              if (searchInfo.isDelFactory) {
                searchInfo.factory = null;
              }
            });
            onPressed?.call();
          }, isDel: searchInfo.isDelFactory);
          children.add(child);
        }
        //物料类型，如原片，辅料，五金
        if (searchInfo.isShowTypeOfMaterial &&
            StringUtils.isNotEmpty(searchInfo.TypeOfMaterial)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).TypeOfMaterial +
                  ":" +
                  searchInfo.TypeOfMaterial!.Name!, () {
            setState(() {
              searchInfo.TypeOfMaterial = null;
              searchInfo.MaterialType = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //请购单号
        if (searchInfo.isShowPurchaseOrderNumber &&
            StringUtils.isNotEmpty(searchInfo.PurchaseOrderNumber)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).PurchaseOrderNumber +
                  ":" +
                  searchInfo.PurchaseOrderNumber!, () {
            setState(() {
              searchInfo.PurchaseOrderNumber = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //采购单号
        if (searchInfo.isPurOrderCode &&
            StringUtils.isNotEmpty(searchInfo.PurOrderCode)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).PurOrderCode +
                  ":" +
                  searchInfo.PurOrderCode!, () {
            setState(() {
              searchInfo.PurOrderCode = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //采购合同号
        if (searchInfo.isPurContractCode &&
            StringUtils.isNotEmpty(searchInfo.PurContractCode)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).PurContractCode +
                  ":" +
                  searchInfo.PurContractCode!, () {
            setState(() {
              searchInfo.PurContractCode = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //子合同号
        if (searchInfo.isPurBodyCode &&
            StringUtils.isNotEmpty(searchInfo.PurBodyCode)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).PurBodyCode2 +
                  ":" +
                  searchInfo.PurBodyCode!, () {
            setState(() {
              searchInfo.PurBodyCode = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //运输合同号
        if (searchInfo.isLContractCode &&
            StringUtils.isNotEmpty(searchInfo.LContractCode)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).LContractCode +
                  ":" +
                  searchInfo.LContractCode!, () {
            setState(() {
              searchInfo.LContractCode = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //承运商
        if (searchInfo.isCarrier &&
            StringUtils.isNotEmpty(searchInfo.CarrierName)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).CarrierName +
                  ":" +
                  searchInfo.CarrierName!, () {
            setState(() {
              searchInfo.CarrierId = "";
              searchInfo.CarrierName = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //种类，如原片种类
        if (searchInfo.isShowSpecies &&
            StringUtils.isNotEmpty(searchInfo.Species?.Name)) {
          Widget child = searchChild(
              context,
              (searchInfo?.SpeciesName ?? "") +
                  ":" +
                  (searchInfo.Species?.Name ?? ""), () {
            setState(() {
              searchInfo.Species = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //品牌，如原片品牌
        if (searchInfo.isShowBrand &&
            StringUtils.isNotEmpty(searchInfo.Brand?.Name)) {
          var showName = searchInfo.BrandName;
          if (StringUtils.isEmpty(showName)) {
            showName = AppStrings.of(context).Brand; //品牌
          }
          Widget child = searchChild(
              context, showName + ":" + searchInfo.Brand!.Name!, () {
            setState(() {
              searchInfo.Brand = null;
              searchInfo.ManufacturerId = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //供应商
        if (searchInfo.isShowSupplier &&
            StringUtils.isNotEmpty(searchInfo.SupplierName)) {
          var showName = AppStrings.of(context).SupplierName;
          Widget child = searchChild(
              context, showName + ":" + searchInfo.SupplierName!, () {
            setState(() {
              searchInfo.SupplierName = "";
              searchInfo.SupplierId = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //采购员
        if (searchInfo.isCreater &&
            StringUtils.isNotEmpty(searchInfo.Creater)) {
          var showName = AppStrings.of(context).PersonName7;
          Widget child = searchChild(
              context, showName + ":" + searchInfo.CreaterName!, () {
            setState(() {
              searchInfo.Creater = "";
              searchInfo.CreaterName = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //部门
        if (searchInfo.isShowDept &&
            StringUtils.isNotEmpty(searchInfo.DeptName)) {
          var showName = AppStrings.of(context).department;
          Widget child =
              searchChild(context, showName + ":" + searchInfo.DeptName!, () {
            setState(() {
              searchInfo.DeptName = "";
              searchInfo.DeptId = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //创建人
        if (searchInfo.isShowFounder &&
            StringUtils.isNotEmpty(searchInfo.FounderName)) {
          Widget child = searchChild(context,
              AppStrings.of(context).Founder! + ":" + searchInfo.FounderName!,
              () {
            setState(() {
              searchInfo.FounderName = null;
              searchInfo.FounderId = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //状态
        if (searchInfo.isShowPurchaseStatus &&
            StringUtils.isNotEmpty(searchInfo.PurchaseStatus?.Name)) {
          var showName = searchInfo.showPurchaseStatusName;
          if (StringUtils.isEmpty(showName)) {
            showName = AppStrings.of(context).State;
          }
          Widget child = searchChild(
              context, showName! + ":" + searchInfo.PurchaseStatus!.Name!, () {
            setState(() {
              searchInfo.PurchaseStatus = null;
              searchInfo.DocumentStatus = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //物料名称
        if (searchInfo.isShowMaterialName &&
            StringUtils.isNotEmpty(searchInfo.MaterialName)) {
          var showName = searchInfo.PreMaterialName;
          if (StringUtils.isEmpty(showName)) {
            showName = AppStrings.of(context).MaterialName3; //物料名称
          }
          Widget child = searchChild(
              context, showName! + ":" + searchInfo.MaterialName!, () {
            setState(() {
              searchInfo.MaterialName = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //合同编号
        if (StringUtils.isNotEmpty(searchInfo.ContractCode)) {
          var showName = searchInfo.showContractCodeName;
          if (StringUtils.isEmpty(showName)) {
            showName = AppStrings.of(context).ContractCode;
          }
          Widget child = searchChild(
              context, showName! + ":" + searchInfo.ContractCode!, () {
            setState(() {
              searchInfo.ContractCode = null;
            });
            onPressed?.call();
          }, isDel: !searchInfo.readOnlyWithContractCode); //合同编号只读的时候，不能删除
          children.add(child);
        }
        //合同外部编号
        if (StringUtils.isNotEmpty(searchInfo.OutCode)) {
          var showNmae = searchInfo.ShowOutCodeName;
          if (StringUtils.isEmpty(showNmae)) {
            showNmae = AppStrings.of(context).OutCode;
          }
          Widget child =
              searchChild(context, showNmae! + ":" + searchInfo.OutCode!, () {
            setState(() {
              searchInfo.OutCode = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //批次号
        if (StringUtils.isNotEmpty(searchInfo.PoCode)) {
          Widget child = searchChild(
              context, AppStrings.of(context).PoCode + ":" + searchInfo.PoCode!,
              () {
            setState(() {
              searchInfo.PoCode = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //订单编号
        if (StringUtils.isNotEmpty(searchInfo.OrderCode)) {
          Widget child = searchChild(context,
              AppStrings.of(context).OrderCode + ":" + searchInfo.OrderCode!,
              () {
            setState(() {
              searchInfo.OrderCode = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //订单外部编号
        if (StringUtils.isNotEmpty(searchInfo.OrderOutCode)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).OrderOutCode +
                  ":" +
                  searchInfo.OrderOutCode!, () {
            setState(() {
              searchInfo.OrderOutCode = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //通知单号
        if (StringUtils.isNotEmpty(searchInfo.NoticeId)) {
          Widget child = searchChild(context,
              AppStrings.of(context).NoticeId + ":" + searchInfo.NoticeId!, () {
            setState(() {
              searchInfo.NoticeId = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //fixme 申请单号
        if (StringUtils.isNotEmpty(searchInfo.ApplicationCode)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).ApplicationCode +
                  ":" +
                  searchInfo.ApplicationCode!, () {
            setState(() {
              searchInfo.ApplicationCode = null;
              searchInfo.Applicationcode = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //fixme 领料单号
        if (StringUtils.isNotEmpty(searchInfo.PickCode)) {
          Widget child = searchChild(context,
              AppStrings.of(context).PickCode + ":" + searchInfo.PickCode!, () {
            setState(() {
              searchInfo.PickCode = null;
              searchInfo.PickCode = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //fixme 申请人
        if (StringUtils.isNotEmpty(searchInfo.UserPerson?.PersonName)) {
          var _name = AppStrings.of(context).ApplyName;
          if (StringUtils.isNotEmpty(searchInfo.showUserPerson)) {
            _name = searchInfo.showUserPerson ?? "";
          }
          Widget child = searchChild(
              context, _name + ":" + "${searchInfo?.UserPerson?.PersonName}",
              () {
            setState(() {
              searchInfo.UserPerson = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //项目名称
        if (StringUtils.isNotEmpty(searchInfo.ProjectName)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).ProjectName +
                  ":" +
                  searchInfo.ProjectName!, () {
            setState(() {
              searchInfo.ProjectName = null;
              searchInfo.Projectname = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //客户名称
        if (StringUtils.isNotEmpty(searchInfo.CustomerName)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).CustomerName +
                  ":" +
                  searchInfo.CustomerName!, () {
            setState(() {
              searchInfo.CustomerName = null;
              searchInfo.Customername = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //规格
        if (StringUtils.isNotEmpty(searchInfo.Size)) {
          Widget child = searchChild(context,
              AppStrings.of(context).Specifications + ":" + searchInfo.Size!,
              () {
            setState(() {
              searchInfo.Size = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //姓名
        if (StringUtils.isNotEmpty(searchInfo.TheName)) {
          Widget child = searchChild(context,
              AppStrings.of(context).TheName + ":" + searchInfo.TheName!, () {
            setState(() {
              searchInfo.TheName = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //加班时长
        if (StringUtils.isNotEmpty(searchInfo.OvertimeHoursStart) ||
            StringUtils.isNotEmpty(searchInfo.OvertimeHoursEnd)) {
          String content = (searchInfo.OvertimeHoursStart ?? "") +
              "~" +
              (searchInfo.OvertimeHoursEnd ?? "");
          Widget child = searchChild(
              context, AppStrings.of(context).OvertimeHours2 + ":" + content,
              () {
            setState(() {
              searchInfo.OvertimeHoursStart = null;
              searchInfo.OvertimeHoursEnd = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //客服经理
        if (StringUtils.isNotEmpty(searchInfo.MerchandiserName)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).MerchandiserName +
                  ":" +
                  searchInfo.MerchandiserName!, () {
            setState(() {
              searchInfo.MerchandiserName = null;
              searchInfo.Merchandisername = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //销售经理
        if (StringUtils.isNotEmpty(searchInfo.SalesmanName)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).SalesmanName +
                  ":" +
                  searchInfo.SalesmanName!, () {
            setState(() {
              searchInfo.SalesmanName = null;
              searchInfo.Salesmanname = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //fixme 所属工序
        if (StringUtils.isNotEmpty(searchInfo.ProcessName)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).ProcessName3 +
                  ":" +
                  searchInfo.ProcessName!, () {
            setState(() {
              searchInfo.ProcessName = null;
              searchInfo.ProcessId = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //fixme 申请班组
        if (StringUtils.isNotEmpty(searchInfo.ApplicationClassName)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).ApplyTeam +
                  ":" +
                  searchInfo.ApplicationClassName!, () {
            setState(() {
              searchInfo.ApplicationClassName = null;
              searchInfo.ApplicationClassId = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //我的工单：设备编码
        if ((searchInfo.isShowDeviceCoding ||
                searchInfo.isShowDeviceCodingWithUi) &&
            StringUtils.isNotEmpty(searchInfo.DeviceCoding)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).Devicecoding +
                  ":" +
                  searchInfo.DeviceCoding!, () {
            setState(() {
              searchInfo.DeviceCoding = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //我的工单：五金领用记录状态
        if (searchInfo.isShowReceivingStatus &&
            StringUtils.isNotEmpty(searchInfo.ReceivingStatusValue)) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).State +
                  ":" +
                  searchInfo.ReceivingStatusValue!, () {
            setState(() {
              searchInfo.ReceivingStatusKey = null;
              searchInfo.ReceivingStatusValue = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //采购申请日期
        if (searchInfo.isShowPurStartDate &&
            StringUtils.isNotEmpty(searchInfo.getPurStartDate())) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).PurStartDate +
                  ":" +
                  searchInfo.getPurStartDate()!, () {
            setState(() {
              searchInfo
                ..BPurStartDate = ""
                ..EPurStartDate = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //采购要货日期
        if (searchInfo.isShowPurEndDate &&
            StringUtils.isNotEmpty(searchInfo.getPurEndDate())) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).PurEndDate +
                  ":" +
                  searchInfo.getPurEndDate()!, () {
            setState(() {
              searchInfo
                ..BPurEndDate = ""
                ..EPurEndDate = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //签订日期
        if (searchInfo.isShowSignSDateTime &&
            StringUtils.isNotEmpty(searchInfo.getSignDateTime())) {
          Widget child = searchChild(
              context,
              AppStrings.of(context).SignDateDate +
                  ":" +
                  searchInfo.getSignDateTime()!, () {
            setState(() {
              searchInfo
                ..SignSDateTime = ""
                ..SignEDateTime = "";
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //添加时间
        if (searchInfo.isShowAddTime &&
            StringUtils.isNotEmpty(searchInfo.getAddTime())) {
          Widget child = searchChild(context,
              AppStrings.of(context).AddTime + ":" + searchInfo.getAddTime()!,
              () {
            setState(() {
              searchInfo
                ..InsertStartDatetime = null
                ..InsertEndDatetime = null;
            });
            onPressed?.call();
          });
          children.add(child);
        }
        //返回空布局
        if (children.length <= 0) {
          return getEmptyView();
        }
        var height = 55.0;
        return Row(
          children: [
            Expanded(
                child: SingleChildScrollView(
              padding: EdgeInsets.zero,
              scrollDirection: Axis.horizontal,
              child: Container(
                height: height,
                alignment: Alignment.center,
                child: Row(
                  children: children,
                ),
              ),
            )),
            Container(
              height: height,
              alignment: Alignment.center,
              child: Row(
                children: [
                  Image.asset(
                    ImagePathUtils.getPathWithImage('ic_gradent_line.png'),
                    height: height,
                  ),
                  InkWell(
                    onTap: () {
                      //清空
                      AppDialog.showDialogWithAlert(context,
                              content: AppStrings.of(context).confirmEmpty)
                          ?.then((value) {
                        if (BoolUtils.isBool(value)) {
                          setState(() {
                            searchInfo?.clear();
                          });
                          onPressed?.call();
                        }
                      });
                    },
                    child: SizedBox(
                      child: Center(
                        child: Padding(
                          padding: EdgeInsets.only(left: 8, right: 16),
                          child: Text(
                            AppStrings.of(context).empty,
                            style: AppStyle.textStyleWithLittle(),
                          ),
                        ),
                      ),
                      height: height,
                    ),
                  )
                ],
              ),
            )
          ],
        );
      },
    );
  }

  ///获取服务器历史记录布局布局
  static Widget getSeverAdressHistoryLayout(
      BuildContext context, ResponseCallbackWithString? onPressed) {
    return StatefulBuilder(
      builder: (BuildContext context, StateSetter setState) {
        List<String>? adressHistory = AppDataConfig.getAdressHistory();
        if (StringUtils.isEmpty(adressHistory)) {
          return getEmptyView();
        }
        List<Widget> children = [];
        adressHistory?.forEach((element) {
          if (StringUtils.isNotEmpty(element)) {
            Widget child = searchChild(context, element!, () {
              //删除
              AppDialog.showDialogWithAlert(context,
                      content: AppStrings.of(context).confirmDelete)
                  ?.then((value) {
                if (BoolUtils.isBool(value)) {
                  setState(() {
                    AppDataConfig.removeAdressHistory(element);
                  });
                }
              });
            }, onTapText: () {
              //文本点击事件
              onPressed?.call(element);
            });
            children.add(child);
          }
        });
        //返回空布局
        if (children.length <= 0) {
          return getEmptyView();
        }
        var height = 55.0;
        return Row(
          children: [
            Expanded(
                child: SingleChildScrollView(
              padding: EdgeInsets.zero,
              scrollDirection: Axis.horizontal,
              child: Container(
                height: height,
                alignment: Alignment.center,
                child: Row(
                  children: children,
                ),
              ),
            )),
            Container(
              height: height,
              alignment: Alignment.center,
              child: Row(
                children: [
                  Image.asset(
                    ImagePathUtils.getPathWithImage('ic_gradent_line.png'),
                    height: height,
                  ),
                  InkWell(
                    onTap: () {
                      //清空
                      AppDialog.showDialogWithAlert(context,
                              content: AppStrings.of(context).confirmEmpty)
                          ?.then((value) {
                        if (BoolUtils.isBool(value)) {
                          setState(() {
                            AppDataConfig.clearAdressHistory();
                          });
                        }
                      });
                    },
                    child: SizedBox(
                      child: Center(
                        child: Padding(
                          padding: EdgeInsets.only(left: 8, right: 16),
                          child: Text(
                            AppStrings.of(context).empty,
                            style: AppStyle.textStyleWithLittle(),
                          ),
                        ),
                      ),
                      height: height,
                    ),
                  )
                ],
              ),
            )
          ],
        );
      },
    );
  }

  ///获取空白组件
  static Widget getEmptyView() {
    return SizedBox.shrink();
  }

  ///获取小圆点
  ///data 底部文本
  ///child 文本上的图标
  static Widget getBadge(String? data, Widget child) {
    // var showBadge = StringUtils.isNotEmpty(data); //是否显示小圆点
    if (data == null) {
      data = "";
    }
    data = data.trim();
    // if (data == '' || data == '0') {
    //   showBadge = false;
    // }
    return LibUi.getBadge(data, child,
        badgeColor: Colors.red,
        borderSideColor: Colors.white,
        borderSideWidth: 1);
    // return aio.Badge(
    //   toAnimate: false,
    //   //具体动画效果
    //   shape: BadgeShape.square,
    //   //BadgeShape.square 方形;BadgeShape.circle 圆形
    //   badgeColor: AppColors.badgeColor,
    //   //颜色
    //   borderRadius: BorderRadius.circular(12),
    //   //圆角
    //   //borderSide: BorderSide(),//圆点边框
    //   padding: EdgeInsets.only(left: 6, right: 6, top: 2, bottom: 2),
    //   //圆点的内补丁
    //   position: BadgePosition.topEnd(top: 0, end: -6),
    //   //控制小圆点的位置
    //   badgeContent: Text(
    //     data!,
    //     style: TextStyle(
    //       color: Colors.white,
    //       fontSize: 12,
    //     ),
    //   ),
    //   //小圆点内容
    //   showBadge: showBadge,
    //   //是否显示小圆点
    //   child: SizedBox(
    //     height: 50,
    //     width: 50,
    //     child: Center(
    //       child: child,
    //     ),
    //   ), //内容子控件
    // );
  }

  ///获取圆形进度圈
  static Widget getCircularProgressIndicator(BuildContext? context,
      {double strokeWidth = 1.0,
      Color valueColor = Colors.lightBlueAccent,
      Color bgColor = Colors.white}) {
    return Container(
      color: bgColor, //背景色
      child: Center(
        child: CircularProgressIndicator(
          backgroundColor: Colors.transparent, //圆圈背景色，默认是透明的。该背景是也是一个圆圈
          strokeWidth: strokeWidth, //圆圈边框宽度,1的效果感觉最好。
          valueColor: AlwaysStoppedAnimation<Color>(valueColor), //圆圈进度只颜色
        ),
      ),
    );
  }

  ///常用Item布局
  static Widget addItem(String title, GestureTapCallback onTap) {
    return Material(
      color: AppColors.backgroundColorWithWhite,
      child: Container(
        child: ListTile(
          title: Text(
            title,
            style: AppStyle.textStyleWithItem(),
          ),
          trailing: getRightGo(),
          onTap: onTap,
        ),
      ),
    );
  }

  ///按钮
  static Widget materialButton(String text,
      {VoidCallback? onPressed,
      double radius = 5,
      double height = 35,
      double width = 50,
      Color color = Colors.blueAccent,
      Color textColor = Colors.white,
      double fontSize = 14,
      EdgeInsetsGeometry margin = const EdgeInsets.only(left: 8, right: 8),
      EdgeInsetsGeometry padding =
          const EdgeInsets.only(left: 16, right: 16)}) {
    return Container(
      margin: margin,
      child: MaterialButton(
        padding: padding,
        height: height,
        minWidth: width,
        onPressed: () {
          onPressed?.call();
        },
        //label 右边控件（一般为文本），不能为空
        color: color,
        //color 按钮颜色
        splashColor: Colors.black12,
        //splashColor 点击时，飞溅扩散的颜色
        //highlightColor: Colors.red, //highlightColor 点击时按钮颜色
        colorBrightness: Brightness.light,
        //colorBrightness 按钮亮度；Brightness.dark 暗系风格;Brightness.light 高亮(默认)
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(radius))),
        //shape 形状
        textColor: Colors.white,
        //文本默认颜色
        child: Text(
          text,
          style: TextStyle(
            color: textColor,
            fontSize: fontSize,
          ),
        ), //fixme 子控件
      ),
    );
  }

  ///边线按钮
  static Widget outlineButton(String text,
      {VoidCallback? onPressed,
      double radius = 5,
      double minHeight = 35,
      double minWidth = 50,
      Color backgroundColor = Colors.white,
      Color textColor = Colors.black,
      double fontSize = 14,
      BorderSide borderSide = const BorderSide(color: Colors.black12, width: 1),
      EdgeInsetsGeometry margin = const EdgeInsets.only(left: 8, right: 8),
      EdgeInsetsGeometry padding =
          const EdgeInsets.only(left: 16, right: 16)}) {
    var outlinedButton = OutlinedButton(
      child: Text(
        text,
        style: TextStyle(
          color: textColor,
          fontSize: fontSize,
        ),
      ),
      onPressed: () {
        onPressed?.call();
      },
      style: ButtonStyle(
        padding: MaterialStateProperty.resolveWith((states) {
          return padding;
        }),
        // ///设置文本不通状态时颜色
        // foregroundColor: MaterialStateProperty.resolveWith(
        //   (states) {
        //     if (states.contains(MaterialState.focused) &&
        //         !states.contains(MaterialState.pressed)) {
        //       //获取焦点时的颜色
        //       return Colors.blue;
        //     } else if (states.contains(MaterialState.pressed)) {
        //       //按下时的颜色
        //       return Colors.deepPurple;
        //     }
        //     //默认状态使用灰色
        //     return Colors.grey;
        //   },
        // ),
        //按钮背景颜色
        backgroundColor: MaterialStateProperty.resolveWith((states) {
          //设置按下时的背景颜色
          // if (states.contains(MaterialState.pressed)) {
          //   return Colors.yellow[300];
          // }
          //默认不使用背景颜色
          return backgroundColor;
        }),

        ///设置水波纹颜色
        overlayColor: MaterialStateProperty.all(Colors.black12),

        ///按钮大小
        minimumSize: MaterialStateProperty.all(Size(minWidth, minHeight)),

        ///设置按钮圆角
        shape: MaterialStateProperty.all(RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(radius))),

        ///设置按钮边框颜色和宽度
        side: MaterialStateProperty.all(borderSide),
      ),
    );
    return Container(
      margin: margin,
      child: outlinedButton,
    );
  }

  ///fixme 显示视频缩略图
  ///playIcon true；图片中间会显示一个播放按钮。
  static Widget videoThumbnailFromFile(BuildContext context, File? videoFile,
      {double width = 100.0,
      double height = 100.0,
      bool playIcon = true,
      double playIconSize = 33,
      Color playIconColor = Colors.white,
      BoxFit fit = BoxFit.cover}) {
    return LibUi.videoThumbnailFromFile(context, videoFile,
        width: width,
        height: height,
        playIcon: playIcon,
        playIconSize: playIconSize,
        playIconColor: playIconColor,
        fit: fit);
  }

  ///拦截返回键，按两次直接退出整个App应用。
  static Widget popScope(BuildContext context, Widget child) {
    return LibUi.popScope(context, child);
  }

  ///列表重写刷新
  static easyRefreshcallRefresh(EasyRefreshController? _controller, {bool delayed = true}) {
    //重新刷新。
    //手动调用下拉刷新
    // IndicatorResult result = IndicatorResult.success; //成功
    // //第二个参数最好设置为true，不然会报错：If you want to modify the result, you can set force to true.
    // _controller?.finishRefresh(result,
    //     true);
    // _controller?.resetFooter();
    // _controller?.callRefresh(force: true)?.then((value) {
    //   print("重新刷新成功");
    // })?.catchError((e) {
    //   print("重新刷新异常：${e}");
    // });
    LibUi.callRefresh(_controller,delayed: delayed);
  }
}

///常用样式
class AppStyle {
  ///标题字体
  static TextStyle textStyleWithTitle() {
    return TextStyle(
      color: Colors.black,
      fontSize: 16,
    );
  }

  ///标题字体,加粗
  static TextStyle textStyleWithTitleBold() {
    return TextStyle(
      color: Colors.black,
      fontWeight: FontWeight.bold,
      fontSize: 16,
    );
  }

  ///标题字体
  static TextStyle textStyleWithTitleWhite() {
    return TextStyle(
      color: Colors.white,
      fontSize: 16,
    );
  }

  ///红色标题字体
  static TextStyle textStyleWithTitleRed() {
    return TextStyle(
      color: Colors.red,
      fontSize: 16,
    );
  }

  ///打卡异常，红色字体
  static TextStyle textStyleWithClockInRed() {
    return TextStyle(
      color: ColorUtils.parseColor("#EF5A25"),
      fontSize: 14,
    );
  }

  ///时间字体
  static TextStyle textStyleWithTimeWhite() {
    return TextStyle(
      color: Colors.white,
      fontSize: 28,
      fontWeight: FontWeight.normal,
    );
  }

  ///小字体
  static TextStyle textStyleWithLittle() {
    return TextStyle(
        color: Colors.black,
        fontSize: 12,
        decoration: TextDecoration.none,
        fontWeight: FontWeight.normal);
  }

  ///item字体
  static TextStyle textStyleWithItem() {
    return TextStyle(
      color: Colors.black,
      fontSize: 16,
    );
  }

  ///条目标题字体
  static TextStyle textStyleWithEntryTitle() {
    return TextStyle(
        color: Colors.black, fontSize: 14, fontWeight: FontWeight.bold);
  }

  static TextStyle textStyleWithEntryTitleBlue() {
    return TextStyle(
      color: Colors.blueAccent,
      fontSize: 14,
    );
  }

  ///条目字体
  static TextStyle textStyleWithEntry() {
    return TextStyle(
      color: Colors.black,
      fontSize: 14,
    );
  }

  ///条目字体
  static TextStyle textStyleWithEntryGrey() {
    return TextStyle(
      color: Colors.grey,
      fontSize: 14,
    );
  }

  ///条目字体
  static TextStyle textStyleWithEntryBlue() {
    return TextStyle(
      color: Colors.blueAccent,
      fontSize: 14,
    );
  }

  ///popu字体
  static TextStyle textStyleWithPopuItem() {
    return TextStyle(
        color: Colors.black,
        fontSize: 16,
        decoration: TextDecoration.none,
        fontWeight: FontWeight.normal);
  }

  ///按钮字体
  static TextStyle textStyleWithButton() {
    return TextStyle(
      color: Colors.white,
      fontSize: 20,
    );
  }

  ///按钮字体
  static TextStyle textStyleWithButtonLittle() {
    return TextStyle(
      color: Colors.white,
      fontSize: 16,
    );
  }

  ///按钮字体
  static TextStyle textStyleWithButtonLittleRed() {
    return TextStyle(
        color: Colors.red, fontSize: 16, fontWeight: FontWeight.bold);
  }

  ///卡片标题字体
  static TextStyle textStyleWithCardTitle() {
    return TextStyle(
        color: Colors.black, fontSize: 16, fontWeight: FontWeight.bold);
  }

  static TextStyle textStyleWithCardTitleRed() {
    return TextStyle(
        color: Colors.red, fontSize: 16, fontWeight: FontWeight.bold);
  }

  static double _fontSize = 16;

  ///卡片字体
  static TextStyle textStyleWithCard({Color color = Colors.black}) {
    return TextStyle(
      color: color,
      fontSize: _fontSize,
    );
  }

  ///卡片字体
  static TextStyle textStyleWithCardBold() {
    return TextStyle(
      fontWeight: FontWeight.bold,
      color: Colors.black,
      fontSize: _fontSize,
    );
  }

  static TextStyle textStyleWithCardBoldRed() {
    return TextStyle(
      fontWeight: FontWeight.bold,
      color: Colors.red,
      fontSize: _fontSize,
    );
  }

  ///卡片字体
  static TextStyle textStyleWithCardRed() {
    return TextStyle(
      color: Colors.red,
      fontSize: _fontSize,
    );
  }

  ///卡片字体
  static TextStyle textStyleWithCardBlue() {
    return TextStyle(
      color: Colors.blueAccent,
      fontSize: _fontSize,
    );
  }

  ///卡片字体
  static TextStyle textStyleWithCardGrey() {
    return TextStyle(
      color: Colors.grey,
      fontSize: _fontSize,
    );
  }

  ///卡片字体
  static TextStyle textStyleWithCardWhite() {
    return TextStyle(
      color: Colors.white,
      fontSize: _fontSize,
    );
  }

  ///Table表格样式
  static TableBorder getTableBorder() {
    return TableBorder.symmetric(
        //fixme 这里的边框 width:0 设置为0，也是有边框的。除非不设置，如：outside: BorderSide.none
        inside: BorderSide(color: Colors.grey, width: 0.5),
        outside: BorderSide(color: Colors.black12, width: 1));
  }

  ///Table 内部表格样式
  static TableBorder getTableBorderInner() {
    return TableBorder.symmetric(
      //fixme 这里的边框 width:0 设置为0，也是有边框的。除非不设置，如：outside: BorderSide.none
      inside: BorderSide(color: Colors.grey, width: 0.5),
      // outside: BorderSide(color: Colors.black12, width: 1)
    );
  }
}

///常用颜色
class AppColors {
  ///服务器地址配置页面主题色
  static Color themeColorWithServerAdress = ColorUtils.parseColor("#09099f");

  ///启动页背景色
  static Color backgroundColorWithLaunch = ColorUtils.parseColor("#09099f");

  ///背景色白色
  static Color backgroundColorWithWhite = Colors.white;

  ///标题栏背景色
  static Color backgroundColorWithTitle = ColorUtils.parseColor("#408BF1");

  ///背景色灰色
  static Color backgroundColorWithGrey = ColorUtils.parseColor("#EAEAEA");

  ///背景色表格标题
  static Color backgroundColorWithTableTitle = Colors.black12;

  ///背景色灰色,表格二级详情背景色
  static Color backgroundColorWithTabelSecondaryTitle =
      ColorUtils.parseColor("#999999");

  ///背景色灰色,表格二级详情背景色
  static Color backgroundColorWithTabelSecondary =
      ColorUtils.parseColor("#EAEAEA");

  ///背景色表格合计
  static Color backgroundColorWithTableAcom = Colors.black12;

  ///灰色横线
  static Color lineColorWithGrey = ColorUtils.parseColor("#EAEAEA");

  ///图标右上角小圆点颜色
  static Color badgeColor = ColorUtils.parseColor("#D52D1F");

  //Table表格，每行的颜色。
  static Color getColorWithTableRow(int postion) {
    if (postion % 2 == 0) {
      return ColorUtils.parseColor("#EEE7E7E7");
    } else {
      return Colors.white;
    }
  }
}

///常用内补丁，外补丁
class AppEdgeInsets {
  ///适配器item内补丁
  static EdgeInsetsGeometry paddingWithItem(
      {double left = 16,
      double right = 16,
      double top = 0,
      double bottom = 0}) {
    return EdgeInsets.only(left: left, right: right, top: top, bottom: bottom);
  }

  ///适配器item内补丁
  static EdgeInsetsGeometry marginWithItem(
      {double left = 48,
      double right = 48,
      double top = 0,
      double bottom = 0}) {
    return EdgeInsets.only(left: left, right: right, top: top, bottom: bottom);
  }

  static double margin_bottom = 8;
}

///单元格宽度
class AppItemExtent {
  static double itemExtent_0 = 30;
  static double itemExtent_1 = 80;
  static double itemExtent_2 = 120;
  static double itemExtent_3 = 200;
}
